package com.pig.graduate.result;

import javafx.beans.binding.ObjectExpression;

import java.util.HashMap;
import java.util.Map;

public class MyResult extends HashMap<String, Object> {

    private static final long serialVersionUID = 1L;

    public MyResult() {
    }

    public static MyResult success(String msg){
        MyResult myResult = new MyResult();
        myResult.put("code",200);
        myResult.put("msg",msg);
        return myResult;
    }

    public static MyResult success(){
        MyResult myResult = new MyResult();
        myResult.put("code",200);
        myResult.put("msg","操作成功");
        return myResult;
    }
    public static MyResult success(Object data){
        MyResult myResult = new MyResult();
        myResult.put("code",200);
        myResult.put("msg","操作成功");
        myResult.put("data",data);
        return myResult;
    }

    public static MyResult success(String msg,Object data){
        MyResult myResult = new MyResult();
        myResult.put("code",200);
        myResult.put("msg",msg);
        myResult.put("data",data);
        return myResult;
    }

    public static MyResult error(String msg){
        MyResult myResult = new MyResult();
        myResult.put("code",500);
        myResult.put("msg",msg);
        return myResult;
    }

    public static MyResult error() {
        return error(500, "未知异常，请联系管理员");
    }

    public static MyResult error(Integer code,String msg){
        MyResult myResult = new MyResult();
        myResult.put("code",code);
        myResult.put("msg",msg);
        return myResult;
    }

    public MyResult put(String key, Object value) {
        super.put(key, value);
        return this;
    }

}
